//
//  OldMapView.m
//  laonianbangSupport
//
//  Created by 勇拓 李 on 18/3/5.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "OldMapView.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import <BaiduMapAPI_Location/BMKLocationService.h>
#import <BaiduMapAPI_Search/BMKGeocodeSearch.h>

@interface OldMapView ()<BMKMapViewDelegate, BMKGeoCodeSearchDelegate, BMKLocationServiceDelegate>
{
    BMKMapView *_mapView;//地图
    BMKLocationService *_locService;//定位
    BMKGeoCodeSearch *_geocodesearch; //地理编码主类，用来查询、返回结果信息
}

@end

@implementation OldMapView

- (instancetype)init
{
    self = [super init];
    if (self) {
        _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
        
        _mapView.showsUserLocation = YES; //是否显示定位图层（即我的位置的小圆点）
        
        _mapView.zoomLevel = 19;//地图显示比例
        
        _mapView.mapType = BMKMapTypeStandard;//设置地图为空白类型
        
        [self addSubview:_mapView];
        
        //
        
        _geocodesearch = [[BMKGeoCodeSearch alloc] init];
        
        _geocodesearch.delegate = self;
        
        [self startLocation];//开始定位方法
        
        UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoMapView:)];
        [_mapView addGestureRecognizer:tapView];
    }
    
    return self;
}

- (void)gotoMapView:(id)sender
{
    [self.delegate gotoDetailMapView];
}

-(void)startLocation

{
    
    //初始化BMKLocationService
    
    _locService = [[BMKLocationService alloc]init];
    
    _locService.delegate = self;
    
    _locService.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    
    //启动LocationService
    
    [_locService startUserLocationService];
    
}

#pragma mark - delegate
- (void)didUpdateUserHeading:(BMKUserLocation *)userLocation

{
    
    NSLog(@"heading is %@",userLocation.heading);
    
}

- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation

{
    
    NSLog(@"didUpdateUserLocation lat %f,long %f",userLocation.location.coordinate.latitude,userLocation.location.coordinate.longitude);
    
    
    [_mapView updateLocationData:userLocation]; //更新地图上的位置
    
    _mapView.centerCoordinate = userLocation.location.coordinate; //更新当前位置到地图中间
    
}

@end
